﻿/* QF classbuilder for Enlib */
using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Logging;

#region SYS_Employee实体类
public class SYS_Employee
{
	private string m_EmplID;
	private string m_EmplName;
	private string m_Sex;
	private DateTime m_Birthday;
	private string m_Mobile;
	private string m_Phone1;
	private string m_Phone2;
	private string m_Email;
	private string m_Messenger;
	private string m_Address;
	private string m_IDCardNo;
	private string m_Description;
	private string m_Logo;
	private string m_Tag;
	private DateTime m_CreateTime;
	private int m_Disabled;
	
	public SYS_Employee ()
	{
		m_EmplID="";
		m_EmplName="";
		m_Sex="";
		m_Birthday=DateTime.Now;
		m_Mobile="";
		m_Phone1="";
		m_Phone2="";
		m_Email="";
		m_Messenger="";
		m_Address="";
		m_IDCardNo="";
		m_Description="";
		m_Logo="";
		m_Tag="";
		m_CreateTime=DateTime.Now;
		m_Disabled=0;
	}
	
	public string EmplID
	{
		get{return m_EmplID;}
		set{m_EmplID=value;}
	}
	public string EmplName
	{
		get{return m_EmplName;}
		set{m_EmplName=value;}
	}
	public string Sex
	{
		get{return m_Sex;}
		set{m_Sex=value;}
	}
	public DateTime Birthday
	{
		get{return m_Birthday;}
		set{m_Birthday=value;}
	}
	public string Mobile
	{
		get{return m_Mobile;}
		set{m_Mobile=value;}
	}
	public string Phone1
	{
		get{return m_Phone1;}
		set{m_Phone1=value;}
	}
	public string Phone2
	{
		get{return m_Phone2;}
		set{m_Phone2=value;}
	}
	public string Email
	{
		get{return m_Email;}
		set{m_Email=value;}
	}
	public string Messenger
	{
		get{return m_Messenger;}
		set{m_Messenger=value;}
	}
	public string Address
	{
		get{return m_Address;}
		set{m_Address=value;}
	}
	public string IDCardNo
	{
		get{return m_IDCardNo;}
		set{m_IDCardNo=value;}
	}
	public string Description
	{
		get{return m_Description;}
		set{m_Description=value;}
	}
	public string Logo
	{
		get{return m_Logo;}
		set{m_Logo=value;}
	}
	public string Tag
	{
		get{return m_Tag;}
		set{m_Tag=value;}
	}
	public DateTime CreateTime
	{
		get{return m_CreateTime;}
		set{m_CreateTime=value;}
	}
	public int Disabled
	{
		get{return m_Disabled;}
		set{m_Disabled=value;}
	}
}
#endregion

#region SYS_Employee管理类
public partial class LogicLayer
{
	public bool AddSYS_Employee(SYS_Employee theSYS_Employee)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "insert into SYS_Employee (EmplID,EmplName,Sex,Birthday,Mobile,Phone1,Phone2,Email,Messenger,Address,IDCardNo,Description,Logo,Tag,CreateTime,Disabled) values (@EmplID,@EmplName,@Sex,@Birthday,@Mobile,@Phone1,@Phone2,@Email,@Messenger,@Address,@IDCardNo,@Description,@Logo,@Tag,@CreateTime,@Disabled)";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@EmplID", DbType.String, theSYS_Employee.EmplID);
			db.AddInParameter(cmd, "@EmplName", DbType.String, theSYS_Employee.EmplName);
			db.AddInParameter(cmd, "@Sex", DbType.String, theSYS_Employee.Sex);
			db.AddInParameter(cmd, "@Birthday", DbType.DateTime, theSYS_Employee.Birthday);
			db.AddInParameter(cmd, "@Mobile", DbType.String, theSYS_Employee.Mobile);
			db.AddInParameter(cmd, "@Phone1", DbType.String, theSYS_Employee.Phone1);
			db.AddInParameter(cmd, "@Phone2", DbType.String, theSYS_Employee.Phone2);
			db.AddInParameter(cmd, "@Email", DbType.String, theSYS_Employee.Email);
			db.AddInParameter(cmd, "@Messenger", DbType.String, theSYS_Employee.Messenger);
			db.AddInParameter(cmd, "@Address", DbType.String, theSYS_Employee.Address);
			db.AddInParameter(cmd, "@IDCardNo", DbType.String, theSYS_Employee.IDCardNo);
			db.AddInParameter(cmd, "@Description", DbType.String, theSYS_Employee.Description);
			db.AddInParameter(cmd, "@Logo", DbType.String, theSYS_Employee.Logo);
			db.AddInParameter(cmd, "@Tag", DbType.String, theSYS_Employee.Tag);
			db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, theSYS_Employee.CreateTime);
			db.AddInParameter(cmd, "@Disabled", DbType.Int32, theSYS_Employee.Disabled);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("AddSYS_Employee:" + ex.Message );
			return false;
		}
	}
	
	public SYS_Employee GetSYS_EmployeeFromDataReader(IDataReader dataReader)
	{
		try
		{
			SYS_Employee result = new SYS_Employee();
			
			if (dataReader["EmplID"] != null && dataReader["EmplID"] != System.DBNull.Value )
				result.EmplID = (string)dataReader["EmplID"];
			if (dataReader["EmplName"] != null && dataReader["EmplName"] != System.DBNull.Value )
				result.EmplName = (string)dataReader["EmplName"];
			if (dataReader["Sex"] != null && dataReader["Sex"] != System.DBNull.Value )
				result.Sex = (string)dataReader["Sex"];
			if (dataReader["Birthday"] != null && dataReader["Birthday"] != System.DBNull.Value )
				result.Birthday = (DateTime)dataReader["Birthday"];
			if (dataReader["Mobile"] != null && dataReader["Mobile"] != System.DBNull.Value )
				result.Mobile = (string)dataReader["Mobile"];
			if (dataReader["Phone1"] != null && dataReader["Phone1"] != System.DBNull.Value )
				result.Phone1 = (string)dataReader["Phone1"];
			if (dataReader["Phone2"] != null && dataReader["Phone2"] != System.DBNull.Value )
				result.Phone2 = (string)dataReader["Phone2"];
			if (dataReader["Email"] != null && dataReader["Email"] != System.DBNull.Value )
				result.Email = (string)dataReader["Email"];
			if (dataReader["Messenger"] != null && dataReader["Messenger"] != System.DBNull.Value )
				result.Messenger = (string)dataReader["Messenger"];
			if (dataReader["Address"] != null && dataReader["Address"] != System.DBNull.Value )
				result.Address = (string)dataReader["Address"];
			if (dataReader["IDCardNo"] != null && dataReader["IDCardNo"] != System.DBNull.Value )
				result.IDCardNo = (string)dataReader["IDCardNo"];
			if (dataReader["Description"] != null && dataReader["Description"] != System.DBNull.Value )
				result.Description = (string)dataReader["Description"];
			if (dataReader["Logo"] != null && dataReader["Logo"] != System.DBNull.Value )
				result.Logo = (string)dataReader["Logo"];
			if (dataReader["Tag"] != null && dataReader["Tag"] != System.DBNull.Value )
				result.Tag = (string)dataReader["Tag"];
			if (dataReader["CreateTime"] != null && dataReader["CreateTime"] != System.DBNull.Value )
				result.CreateTime = (DateTime)dataReader["CreateTime"];
			if (dataReader["Disabled"] != null && dataReader["Disabled"] != System.DBNull.Value )
				result.Disabled = (int)dataReader["Disabled"];
			
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetReaderSYS_Employee:" + ex.Message);
			return null;
		}
	}
	
	public SYS_Employee GetSYS_Employee(string EmplID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * From SYS_Employee where EmplID=@EmplID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@EmplID", DbType.String, EmplID);
			
			SYS_Employee result = null;
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				if (dataReader.Read())
				{
					result = GetSYS_EmployeeFromDataReader( dataReader );
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetSYS_Employee:" + ex.Message);
			return null;
		}
	}
	
	public bool DelSYS_Employee(string EmplID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "delete From SYS_Employee where EmplID=@EmplID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@EmplID", DbType.String, EmplID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("DelSYS_Employee:" + ex.Message);
			return false;
		}
	}
	
	public bool UpdateSYS_Employee(SYS_Employee theSYS_Employee)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "update SYS_Employee set EmplName=@EmplName,Sex=@Sex,Birthday=@Birthday,Mobile=@Mobile,Phone1=@Phone1,Phone2=@Phone2,Email=@Email,Messenger=@Messenger,Address=@Address,IDCardNo=@IDCardNo,Description=@Description,Logo=@Logo,Tag=@Tag,CreateTime=@CreateTime,Disabled=@Disabled where EmplID=@EmplID";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@EmplName", DbType.String, theSYS_Employee.EmplName);
			db.AddInParameter(cmd, "@Sex", DbType.String, theSYS_Employee.Sex);
			db.AddInParameter(cmd, "@Birthday", DbType.DateTime, theSYS_Employee.Birthday);
			db.AddInParameter(cmd, "@Mobile", DbType.String, theSYS_Employee.Mobile);
			db.AddInParameter(cmd, "@Phone1", DbType.String, theSYS_Employee.Phone1);
			db.AddInParameter(cmd, "@Phone2", DbType.String, theSYS_Employee.Phone2);
			db.AddInParameter(cmd, "@Email", DbType.String, theSYS_Employee.Email);
			db.AddInParameter(cmd, "@Messenger", DbType.String, theSYS_Employee.Messenger);
			db.AddInParameter(cmd, "@Address", DbType.String, theSYS_Employee.Address);
			db.AddInParameter(cmd, "@IDCardNo", DbType.String, theSYS_Employee.IDCardNo);
			db.AddInParameter(cmd, "@Description", DbType.String, theSYS_Employee.Description);
			db.AddInParameter(cmd, "@Logo", DbType.String, theSYS_Employee.Logo);
			db.AddInParameter(cmd, "@Tag", DbType.String, theSYS_Employee.Tag);
			db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, theSYS_Employee.CreateTime);
			db.AddInParameter(cmd, "@Disabled", DbType.Int32, theSYS_Employee.Disabled);
			db.AddInParameter(cmd, "@EmplID", DbType.String, theSYS_Employee.EmplID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("UpdateSYS_Employee:" + ex.Message);
			return false;
		}
	}
	
	public List<SYS_Employee> ListSYS_Employee()
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * from SYS_Employee";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			 List<SYS_Employee> result = new  List<SYS_Employee>();
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				while (dataReader.Read())
				{
					SYS_Employee obj = GetSYS_EmployeeFromDataReader( dataReader );
					if(obj != null)
						result.Add(obj);
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("ListSYS_Employee:" + ex.Message);
			return null;
		}
	}
	
}
#endregion